// formPackage/pages/feedBackList/feedBackList.js
import { feedBackList, dealSuggestIsEffective } from "../../../service/config"
import { suggestReportHouseList, suggestReportHouseDeal } from "../../../service/user_service"
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    page: 0,
    pageSize: 200,
    dataList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.suggestReportHouseList();
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
  },
  //查询列表
  suggestReportHouseList() {
    wx.showLoading();
    suggestReportHouseList(this.data.page, this.data.pageSize).then(res => {
      wx.hideLoading();
      console.log("JJLog:列表是==:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          dataList: res.data || []
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
      console.error("JJLog:suggestReportHouseList", err);
    })
  },
  busDealAction(e) {
    let item = e.currentTarget.dataset.item;
    app.globalData.suggestData = item;
    wx.navigateTo({
      url: '/formPackage/pages/feedBackDetail/feedBackDetail',
    })
  },
  callPhoneAction(e) {
    let phone = e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
      fail: err => {

      }
    })
  },
  //跳转到详情:
  pushToHouseDetail(e) {
    let item = e.currentTarget.dataset.item;
    let houseNumber = item.number;
    let houseType = item.houseType;
    if (houseType == 1) {
      wx.navigateTo({
        url: '/newHousePackage/pages/newHouseDetail/newHouseDetail?houseNumber=' + houseNumber,
      })
    }
  },
  //处理这个投诉意见是否有效
  dealSuggestIsEffectiveAction(e) {
    let index = e.currentTarget.dataset.index;
    // let type = e.currentTarget.dataset.type;
    let item = this.data.dataList[index];
    // console.log("JJLog:item是:" + JSON.stringify(item));
    wx.showModal({
      title: '提示',
      content: '确认已处理该房源错误信息?',
      confirmColor: "#FF0000",
      success: res => {
        if (res.confirm) {
          this.suggestReportHouseDeal(item.id, true, index);
        }
      }
    })


  },
  suggestReportHouseDeal(id, type, index) {
    wx.showLoading();
    suggestReportHouseDeal(id).then(res => {
      wx.hideLoading();
      if (res.code == 200) {
        let item = 'dataList[' + index + '].isDeal';
        this.setData({
          [item]: true,
        })
        wx.showToast({
          title: "操作成功",
          icon: "success"
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "操作失败",
        icon: "none"
      })
      console.error("JJLog:suggestReportHouseDeal", err);
    })
  },







})